# -*- coding: utf-8 -*-

import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *


class MainWindow(QWidget):

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent=parent)

        groupBox = QGroupBox("Checkboxes")
        groupBox.setFlat(True)

        layout = QHBoxLayout()
        self.checkBox1 = QCheckBox("&Checkbox1")
        self.checkBox1.setChecked(True)
        self.checkBox1.stateChanged.connect(lambda : self.btnstate(self.checkBox1))
        layout.addWidget(self.checkBox1)

        self.checkBox2 = QCheckBox("Checkbox2")
        self.checkBox2.toggled.connect(lambda : self.btnstate(self.checkBox2))
        layout.addWidget(self.checkBox2)

        self.checkBox3 = QCheckBox("Checkbox3")
        self.checkBox3.setTristate(True)
        self.checkBox3.setCheckState(Qt.PartiallyChecked)
        self.checkBox3.stateChanged.connect(lambda : self.btnstate(self.checkBox3))
        layout.addWidget(self.checkBox3)

        groupBox.setLayout(layout)
        mainLayout = QVBoxLayout()
        mainLayout.addWidget(groupBox)

        self.setLayout(mainLayout)
        self.setWindowTitle("CheckBox Demo")

    def btnstate(self, btn):
        print("%s: %s\n %s: %s\n %s: %s" % (self.checkBox1.text(),
                                        str(self.checkBox1.isChecked()),
                                        self.checkBox2.text(),
                                        str(self.checkBox2.isChecked()),
                                        self.checkBox3.text(),
                                        str(self.checkBox3.isChecked())))


if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = MainWindow()
    win.show()
    sys.exit(app.exec())